package com.yc.cloud.admin.controller;

import com.yc.cloud.common.basic.api.ResponseResult;
import com.yc.cloud.common.orm.CommonPage;
import com.yc.cloud.common.basic.dto.BasePageReqDTO;
import com.yc.cloud.admin.dto.request.HwCameraRecordingLogCreateReqDTO;
import com.yc.cloud.admin.dto.request.HwCameraRecordingLogUpdateReqDTO;
import com.yc.cloud.admin.vo.HwCameraRecordingLogVo;
import com.yc.cloud.admin.service.HwCameraRecordingLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;

/**
 * <p>
 * 摄像头录制任务执行日志表 前端控制器
 * </p>
 *
 * @author kinggu
 * @since 2025-09-15
 */
@RestController
@Api(tags = "摄像头录制任务执行日志表")
@RequestMapping("/hw-camera-recording-logs")
public class HwCameraRecordingLogController {

    @Resource
    private HwCameraRecordingLogService hwCameraRecordingLogService;

    @ApiOperation("创建摄像头录制任务执行日志表")
    @PostMapping
    public ResponseResult<HwCameraRecordingLogVo> create(@Validated @RequestBody HwCameraRecordingLogCreateReqDTO createReqDTO) {
        HwCameraRecordingLogVo newVo = hwCameraRecordingLogService.create(createReqDTO);
        if (newVo != null) {
            return ResponseResult.success(newVo);
        }
        return ResponseResult.failed("创建失败");
    }

    @ApiOperation("更新摄像头录制任务执行日志表")
    @PutMapping("/{id}")
    public ResponseResult<HwCameraRecordingLogVo> update(@PathVariable("id") Long id, @Validated @RequestBody HwCameraRecordingLogUpdateReqDTO updateReqDTO) {
        updateReqDTO.setId(id);
        HwCameraRecordingLogVo updatedVo = hwCameraRecordingLogService.update(updateReqDTO);
        if (updatedVo != null) {
            return ResponseResult.success(updatedVo);
        }
        return ResponseResult.failed("更新失败");
    }

    @ApiOperation("删除摄像头录制任务执行日志表")
    @DeleteMapping("/{id}")
    public ResponseResult<Boolean> delete(@PathVariable("id") Long id) {
        boolean success = hwCameraRecordingLogService.delete(id);
        if (success) {
            return ResponseResult.success(true);
        }
        return ResponseResult.failed("删除失败");
    }

    @ApiOperation("获取摄像头录制任务执行日志表详情")
    @GetMapping("/{id}")
    public ResponseResult<HwCameraRecordingLogVo> getById(@PathVariable("id") Long id) {
        return ResponseResult.success(hwCameraRecordingLogService.getVOById(id));
    }

    @ApiOperation("分页查询摄像头录制任务执行日志表")
    @GetMapping
    public ResponseResult<CommonPage<HwCameraRecordingLogVo>> list(@Validated BasePageReqDTO pageReqDTO) {
        return ResponseResult.success(hwCameraRecordingLogService.list(pageReqDTO));
    }
}
 